﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Wpf.CommonTools.SystemExtension
{
    /// <summary>
    /// 
    /// </summary>
    public class MyEventLog
    {
        private string source;
        /// <summary>
        /// 
        /// </summary>
        public string Source
        {
            get { return source; }
            set { source = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        public MyEventLog(string source)
        {
            this.source = source;
            if (!EventLog.SourceExists(source))
            {
                EventLog.CreateEventSource(source, "MyLog");
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entry"></param>
        public void Insert(string entry)
        {
            EventLog myLog = new EventLog();
            myLog.Source = source;
            myLog.WriteEntry(entry);
            myLog.WriteEntry(entry);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ex"></param>
        public void Insert(Exception ex)
        {
            EventLog myLog = new EventLog();
            myLog.Source = source;
            myLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="type"></param>
        /// <param name="eventID"></param>
        /// <param name="category"></param>
        public void Insert(string entry, EventLogEntryType type, int eventID, short category)
        {
            EventLog myLog = new EventLog();
            myLog.Source = source;
            myLog.WriteEntry(entry, type, eventID, category);
        }


    }
}
